<!--
 * @Author: your name
 * @Date: 2020-05-12 17:07:31
 * @LastEditTime: 2020-06-11 16:16:59
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \v1.0.0\components\kmlc-com\kmlc-form-view-select-person\kmlc-form-view-select-person.vue
 -->
<template>
  <view>
    <kmlc-form-tree-select :label="label" :em-data="emData_" @onChangeVal="onChangeVal"></kmlc-form-tree-select>
  </view>
</template>


<script>
import { queryAddressBook } from "@/pages/customForm/interface.js";
export default {
  props: {
    label: {
      type: String
    },
    emData: {
      type: Object,
      default: () => {
        return {};
      }
    },
    readonly: {
      type: Boolean,
      default: false
    },
    options: {
      type: Object,
      default: () => {
        return {};
      }
    },
    rules: {
      type: Array,
      default: () => {
        return [];
      }
    },
    model: {
      type: String
    },
    keyStr: {
      type: String
    }
  },

  data() {
    return {
      emData_: {},
      personData: [],
      value: []
    };
  },
  created() {
    this.queryAddressBooks();
  },
  watch: {
    value(val) {}
  },
  methods: {
    initEmData() {
      if (this.emData && this.emData.key) {
        this.emData_ = this.emData;
        this.emData_["options"]["options"] = this.personData;
      } else {
        this.emData_["options"] = this.options;
        this.emData_["rules"] = this.rules;
        this.emData_["model"] = this.model;
        this.emData_["key"] = this.keyStr;
      }
    },
    async queryAddressBooks() {
      const params = {};
      const Res = await queryAddressBook(params);
      if (Res && Res.success) {
        this.personData = Res.result;

        this.initEmData();
      } else {
        uni.showToast({
          title: Res.message || "数据获取失败~！",
          icon: "none"
        });
      }
    },
    onChangeVal(data) {
      console.log(data);
      this.value = data;
      this.$emit("onChangeVal", data);
    }
  },
  modal: {
    prop: "value",
    event: "onChangeVal"
  }
};
</script>

<style lang="scss">
  .isrequire{ color:#d41200;}
</style>